package org.wisdom.ac.interceptor;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.wisdom.ac.apis.UserController;
import org.wisdom.ac.dto.UserDto;
import org.wisdom.context.WisdomContextHolder;

import lombok.AllArgsConstructor;
import org.wisdom.vo.ResponseResult;

/**
 * @author 张智研
 * @date 2023/04/23 16:42
 **/
@Component
@AllArgsConstructor
@Aspect
public class WisdomControllerAdvice {

    private UserController userController;

    @Before("@annotation(org.wisdom.annotation.WisdomController)")
    public void doProcess(JoinPoint joinPoint) {
        ResponseResult<UserDto> responseResult = userController.getInfo();
        if(responseResult.getCode() == 0) {
            UserDto userDto = responseResult.getDs();
            WisdomContextHolder.getContext().setCompanyId("测试");
            WisdomContextHolder.getContext().setDeptId("测试");
            WisdomContextHolder.getContext().setDeptPath("测试");
        }
    }
    @Around("@annotation(org.wisdom.annotation.EnableDataFilter)")
    public Object doProcess(ProceedingJoinPoint joinPoint) throws Throwable {
        ResponseResult<UserDto> responseResult = userController.getInfo();
        if(responseResult.getCode() == 0) {
            UserDto userDto = responseResult.getDs();
            WisdomContextHolder.getContext().setCompanyId("测试");
            WisdomContextHolder.getContext().setDeptId("测试");
            WisdomContextHolder.getContext().setDeptPath("测试");
        }
        return joinPoint.proceed();
    }

}